home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5312 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: cville-srv.wam.umd.edu!jsquires
  2. From: jsquires@wam.umd.edu (jeffrey d squires)
  3. Newsgroups: comp.lang.c
  4. Subject: Limit on #bytes inside of struct?
  5. Date: 9 Feb 1996 22:01:20 GMT
  6. Organization: University of Maryland College Park
  7. Message-ID: <4fgg7g$r36@cville-srv.wam.umd.edu>
  8. NNTP-Posting-Host: rac4.wam.umd.edu
  9. X-Newsreader: TIN [version 1.2 PL0]
  10.  
  11. I previously wrote:
  12.         >
  13.         >I have the following:
  14.         >
  15.         >typedef struct {
  16.         >        int zero;
  17.         >        int one;
  18.         >        int two;
  19.         >        int three;
  20.         >        int four;
  21.         >        int five;
  22.         >        int six;
  23.         >        int seven_or_more;
  24.         >} hist_type;
  25.         >
  26.         >hist_type histogram;
  27.         >int num=2;
  28.         >
  29.         >histogram.zero = 0;
  30.         >histogram.one = 0;
  31.         >histogram.two = 0;
  32.         >histogram.three = 0;
  33.         >histogram.four = 0;  /* at this point, value of num changes from 2 to 0
  34. !!!*/
  35.         >
  36.         >Is there a limit on the number of bytes allowed inside of a struct?
  37.         >I am positive that the value of num changes from 2 before the last
  38.         >assignment to 0 after it.  Any ideas?  Is this a bug in gcc?  Unix?
  39.         >
  40.         >This is completely crazy!
  41.         >
  42.  
  43.  
  44. What I left out was that I tried to do this:
  45.  
  46. #define NUM_PASSES 3
  47.  
  48.  
  49. .
  50. .
  51. .
  52. .
  53. .
  54.  
  55.  
  56.  
  57.  
  58. hist_type histogram[NUM_PASSES];  /* BIIIIIG MISTAKE */
  59.  
  60. I tried to have the above example be simple, but it appears that I left
  61. out the part that contained the problem.  I guess that you can;t
  62. declare an array with the size defined by #define.  I had to do:
  63.  
  64. hist_type * histogram;
  65. histogram = .... malloc(NUM_PASSES * ......
  66.  
  67. That worked, and my problem is solved.  Thanks everyone for responding
  68. Sorry to be unclear.
  69.  
  70. Jeff Squires
  71. jsquires@wam.umd.edu
  72.  
  73.